package com.gewu.pm.ui.dialog;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.StringRes;

import com.gewu.pm.R;
import com.gewu.pm.aop.SingleClick;
import com.hjq.base.BaseDialog;
/**
 * 通用提示弹框 单按钮
 */
public class TipsDialog {
    public static final class Builder
            extends BaseDialog.Builder<Builder> {

        private OnListener mListener;
        private final TextView tvTitle;//标题
        private final TextView tvContent;//内容

        private final Button btConfirm;//确定按钮

        public Builder(Context context) {
            super(context);
            setContentView(R.layout.dialog_tips);
            setAnimStyle(BaseDialog.ANIM_SCALE);
            setCanceledOnTouchOutside(false);//点击背景不关闭
            tvTitle = findViewById(R.id.tv_title);
            tvContent = findViewById(R.id.tv_content);
            btConfirm = findViewById(R.id.bt_confirm);
            setOnClickListener(btConfirm);

        }

        /**
         * 设置标题
         */
        public Builder setTitle(@StringRes int id) {
            return setTitle(getString(id));
        }

        public Builder setTitle(CharSequence text) {
            tvTitle.setText(text);
            return this;
        }

        /**
         * 设置内容
         */
        public Builder setContent(@StringRes int id) {
            return setContent(getString(id));
        }

        public Builder setContent(CharSequence text) {
            tvContent.setText(text);
            return this;
        }
        /**
         * 设置按钮文字
         */
        public Builder setButtonText(@StringRes int id) {
            return setButtonText(getString(id));
        }

        public Builder setButtonText(CharSequence text) {
            btConfirm.setText(text);
            return this;
        }

        public Builder setListener(OnListener listener) {
            mListener = listener;
            return this;
        }

        @SingleClick
        @Override
        public void onClick(View v) {
            if (v == btConfirm) {//确定
                dismiss();
                if (mListener != null) {
                    mListener.onConfirm(getDialog());
                }
            }

        }
    }

    public interface OnListener {

        /**
         * 确定
         */
        void onConfirm(BaseDialog dialog);
    }
}